package com.enhe.gck.controller;

import com.enhe.gck.CarbonBaseConstant;
import com.enhe.gck.CarbonEnumKeyValue;
import com.enhe.gck.CarbonRelationType;
import com.enhe.gck.communal.PublicMethod;
import com.enhe.gck.item.AppOrderRecordHWANE22617Item;
import com.enhe.gck.item.PouringOrderHWANE18490Item;
import com.enhe.gck.item.SupplyOrderHWANE16829Item;
import com.enhe.gck.pojo.AppOrderRecord;
import com.enhe.gck.pojo.SupplyOrder;
import com.kuangkie.carbon.common.IntegrationMsg;
import com.kuangkie.carbon.panel.CarbonPanel;
import com.kuangkie.carbon.record.FGRecordComplexusBuilder;
import com.kuangkie.carbon.record.ProRecordBuilder;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("addAppRecord")
public class AppController {
//    @PostMapping("/addAppRecord")
//    private List<AppOrderRecord> addAppRecord(@RequestBody String[] appOrderId) {
//
//        CarbonPanel.changeCurrentProgram(366042330866425862L);
//        List<AppOrderRecord> a = new ArrayList<>();
//        for (String id : appOrderId) {
//            AppOrderRecord records = new AppOrderRecord();
////            SupplyOrder order = CarbonPanel.getRecordDiscover(CarbonBaseConstant.供货订单_ghdd).getRecord(String.valueOf(id))(SupplyOrder.class,2);
//            SupplyOrder order = CarbonPanel.getRecordQueryFactory(CarbonBaseConstant.供货订单_ghdd)
//                    .getProConJunctionFactory().addEqual(SupplyOrderHWANE16829Item.供货订单_基本属性组, id)
//                    .goBack().queryABean(SupplyOrder.class, 2);
//            if (order != null) {
//                records.setSupplier(order.getCustomer().getName());
//                records.setOrderCode(order.getSupplyOrderBig().getOrder());
//                records.setMateral(order.getMaterial().getName());
//                records.setOrderId(order.getOrder());
//                records.setCarNumber(order.getCar().getCarNo());
//                records.setGetGoodsCode(order.getPickupCode());
//                IntegrationMsg msg = CarbonPanel.getRecordIntegration(CarbonBaseConstant.供应商app下单记录_最新__gysxdjlzx).integrate(records);
//                a.add(records);
//            }
//        }
//        return a;
//    }

    @PostMapping("/addAppRecord")
    private boolean addAppRecord(@RequestBody String[] appOrderId) {
        CarbonPanel.changeCurrentProgram(366042330866425862L);
        if(appOrderId!=null&&appOrderId.length>0){
            SupplyOrder info=PublicMethod.getInfo(CarbonBaseConstant.供货订单_ghdd,appOrderId[0],SupplyOrder.class,2);
            FGRecordComplexusBuilder fGRecordComplexusBuilder=CarbonPanel.getFGRecordComplexusBuilder();
            ProRecordBuilder order=fGRecordComplexusBuilder.getProRecordBuilder(CarbonBaseConstant.供应商app下单记录_最新__gysxdjlzx);
            order.putAttribute(AppOrderRecordHWANE22617Item.基本属性组_批量下单数,appOrderId.length);
            order.addRelation(CarbonRelationType.RR_供应商app下单记录_最新__供货商_客户管理,info.getCustomer().getRecordCode());
            for (String id : appOrderId) {
                order.addRelation(CarbonRelationType.RR_供应商app下单记录_最新__单号_供货订单,id);
            }
            IntegrationMsg msg=CarbonPanel.getRecordIntegration(CarbonBaseConstant.供应商app下单记录_最新__gysxdjlzx)
                    .integrate(fGRecordComplexusBuilder.getFGRecordComplexus());
            return msg.success();
        }
        return true;
    }
}
